﻿#include "library.au3"

Global $win = "League of Legends (TM) Client"
Global $hWnd = WinActivate($win)
Global $winPos = WinGetPos($win)

Global $autoHeat = 0
Global $autoHeatLevel = 80
Global $autoHeatDelay = TimerInit()

Global $keyAPressed = 0
Global $keyBPressed = 0
Global $keyCPressed = 0

FFSetWnd($hWnd, False)

While True
   $hWnd = WinActive($win)
   If $hWnd = 0 Then
	  Sleep(100)
	  ContinueLoop
   EndIf

   Local $hDLL = DllOpen("user32.dll")

   Local $heat = GetHeat()
   ;ToolTip("Heat : " & $heat, $winPos[0] + 600, $winPos[1] + 650)
   If ($autoHeat And $heat < $autoHeatLevel) Then
	  If (TimerDiff($autoHeatDelay) > 100) Then
		 If ($autoHeatLevel = 40) Then
			Send("w")
		 Else
			Send("q")
		 EndIf

		 $autoHeatDelay = TimerInit()
	  EndIf
   EndIf

   If _IsPressed("20", $hDLL) = 1 Then
	  If $keyAPressed = 0 Then
		 If $autoHeat = 1 Then
			$autoHeat = 0
		 Else
			$autoHeat = 1
		 EndIf

	  EndIf

	  $keyAPressed = 1
   Else
	  $keyAPressed = 0
   EndIf

   If _IsPressed("21", $hDLL) = 1 Then
	  If $keyBPressed = 0 Then
		 $autoHeatLevel = $autoHeatLevel + 20
		 ToolTip("autoHeatLevel : " & $autoHeatLevel, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyBPressed = 1
   Else
	  $keyBPressed = 0
   EndIf

   If _IsPressed("22", $hDLL) = 1 Then
	  If $keyCPressed = 0 Then
		 $autoHeatLevel = $autoHeatLevel - 20
		 ToolTip("autoHeatLevel : " & $autoHeatLevel, $winPos[0] + 100, $winPos[1] + 5)
	  EndIf
	  $keyCPressed = 1
   Else
	  $keyCPressed = 0
   EndIf

   DllClose($hDLL)
WEnd

Func GetHeat()
   Local $colorCount = FFColorCount(0x050505, 10, True, 499, 730, 816, 731)
   ;ToolTip("ColorCount : " & $colorCount, $winPos[0] + 600, $winPos[1] + 650)

   If $colorCount >= 564 Then
	  Return 0
   EndIf

   If $colorCount >= 554 Then
	  Return 5
   EndIf

   If $colorCount >= 521 Then
	  Return 10
   EndIf

   If $colorCount >= 496 Then
	  Return 15
   EndIf

   If $colorCount >= 456 Then
	  Return 20
   EndIf

   If $colorCount >= 426 Then
	  Return 25
   EndIf

   If $colorCount >= 387 Then
	  Return 30
   EndIf

   If $colorCount >= 359 Then
	  Return 35
   EndIf

   If $colorCount >= 318 Then
	  Return 40
   EndIf

   If $colorCount >= 313 Then
	  Return 45
   EndIf

   If $colorCount >= 276 Then
	  Return 50
   EndIf

   If $colorCount >= 266 Then
	  Return 55
   EndIf

   If $colorCount >= 237 Then
	  Return 60
   EndIf

   If $colorCount >= 207 Then
	  Return 65
   EndIf

   If $colorCount >= 168 Then
	  Return 70
   EndIf

   If $colorCount >= 137 Then
	  Return 75
   EndIf

   If $colorCount >= 108 Then
	  Return 80
   EndIf

   If $colorCount >= 77 Then
	  Return 85
   EndIf

   If $colorCount >= 45 Then
	  Return 90
   EndIf

   If $colorCount >= 27 Then
	  Return 95
   EndIf

   Return 100
EndFunc
